\chapter{$\pi$ Calculus}
\section{Introduction}
%\subsection{Intoduction}
The $\lambda$ calculus\cite{Barendregt} is restricted to formulating the notion of sequential interaction in a clean mathematical and formal way. The technological advances has brought a significant change in computing practice giving rise to interactive systems. People, computers and softwares utilize mobility continuously. Thus $\pi$ calculus was developed in the late 1980s in order to express mobile systems accurately. Thus the $\pi$-calculus is a more complete way of formalizing real world systems, in which the elements alter as they interact. \\
$\pi$ calculus is mainly a model of {\it processes} which are interconnected through {\it channels}. A $process$ is an abstraction for an independent thread of control. Whereas a channel is an abstraction of the communicating link between the two process. The basic computation step in $\pi$ calculus is the transfer of a communication link between two processes, the receiver can then use this link to carry out future communication.  
CCS(Concurrent Communication Systems) is quite basic and includes channels and processes where names can be transferred via channels from one process to other. $\pi$-calculus made an addition by adding mobility of channels i.e transferring channels from one process to other process. Thus the connectivity of the system can change dynamically.% The $\pi$-calculus uses the notion of mobility of channels because it can successfully model the movement of processes.% and it is simple.
$\pi$-calculus differs from other process calculi in the fact that local variables are 'movable'. This means that a $process$ can transfer a local $channel$ to other $process$ and this $channel$ will be used as a local $channel$ by the receiving $process$. There are some aspects of $\pi$ calculus which are not modeled in this thesis. Some of them are modal logics and analysis algorithms.
\section{Syntax and Mobility}
$\pi$-calculus is simple yet very powerful. It can successfully model complex networks like the whole of Internet or network protocols. The capacity to change the connectivity of the network is the crucial difference between $\pi$-calculus and concurrent communicating systems(CCS). \\
The system consists of processes and channels. Each channel connects two processes and establishes connection between them. Processes can be connected virtually like in Internet systems with indirect links.\\
Mobility in this system can be introduced in many ways, some of them are:
\begin{enumerate}
\item Processes move in the physical environment
\item Processes move in the virtual space 
\item Channels move in the virtual space	 
\end{enumerate}
The movement of processes in physical space can be modeled in the virtual space, so choice 1 reduces to choice 2. Also, moving a process in the virtual space essentially means changing some link. This can in turn be modeled by moving a channel. Hence, modelling only choice 3 will essentially reflect all three types of mobility mentioned above. \\
$\pi$ calculus assumes an infinite set of names N which will be used to name variables, data values or communication channels. A process could be of the following form.
\begin{itemize}
  \item {\it Empty Process (0)} : The process which cannot perform any actions
  \item {\it Input Process (a(x).P)} : A name is received along the channel {\bf a} and the variable/channel {\bf x} is bound to this value and then acts as P
  \item {\it Output Process ($\bar{a}<x>$.P)} : The value {\bf x} is sent along the channel {\bf a} and then acts as P
  \item {\it Scope (({\it v}x)P}) : This limits the scope of {\bf x} to P only
  \item {\it Choice Operator (P+Q)} : The agent chooses non-deterministically to proceed as process P or process Q
  \item {\it Parallel Composition (P $|$Q)} : The two processes P and Q proceed simultaneously 
  \item {\it Replication (!P)} : Denotes infinite number of copies of P, all running in parallel
\end{itemize}
\section{An Example}
Consider a system with clients C1 and C2, a server S and a printer P. Now, S is connected to C1, C2 and P via channels 'b', 'c', and 'a' respectively(State 1). Suppose C1 sends a request to S via channel 'b' to connect to the printer. S responds by sending channel 'a' across 'b'. The system now looks like figure 2. \\
\begin{figure}
  \parbox{2.4in}{%
    \includegraphics[width=2.4in]{figures/example_fig1.pdf}
    \caption{State 1}%
    \label{fig:2figsA}}%
  \qquad
  \begin{minipage}{2.4in}%
    \includegraphics[width = 2.4in]{figures/example_fig2.pdf}
    \caption{State 2}%
    \label{fig:2figsB}%
  \end{minipage}
\end{figure}
Accoring to the $\pi$ calculus syntax, the server S, uses the choice operator and waits for request from C1 and C2.
\begin{center}
S = c(m$_1$).S$_1$ + b(m$_2$).S$_2$
\end{center}
Without loss of generality, suppose C1 is chosen to proceed with the connection. Now the server is in state S$_2$ \\
S sends channel 'a' along channel 'b'. Using output process, C1 receives channel 'a' along 'b' and stores it in 'd'. This can be expressed in $\pi$-calculus syntax as:
\begin{center}
b$<a>$.S $||$ b(d).C1   
\end{center}
Now the system transforms to State 2 as shown in figure 3.2. When the printing job by C1 is done, C1 and S synchronize on b and connection between P and S is re-established.\\
The above example shows the input and output processes in action along with the parallel operation. 
